<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="/resource/css/index_work.css">

<script type="text/javascript" src="/resource/js/jquery-3.2.1/jquery.js"></script>
</head>
<body>
<button type="button" onclick="add()">添加</button>
	<table>
		<tr>
			<td>编号</td>
			<td>姓名</td>
			<td>爱好</td>
			<td>操作</td>
		</tr>
		<c:forEach items="${list }" var="s">
			<tr>
				<td>${s.id }</td>
				<td>${s.name }</td>
				<td>
					<c:forEach items="${s.favs}" var="fav" varStatus="index">
						${index.index>0?',':''} ${fav.name}
					</c:forEach>
				</td>
				<td>
					<input type="button" value="编辑" onclick="update(${s.id})">
					<input type="button" value="删除" onclick="deletes(${s.id})">
				</td>

			</tr>
		</c:forEach>
	</table>
</body>
<script type="text/javascript">
	function add(){
		location.href="./toadd";
	}
	
	function update(id){
		location.href="./toupdate?id="+id;
	}
	
	function deletes(id){
		$.post("/del",{id:id},function(data){
			if(data){
				alert("删除成功");
				location.href="list";
			}else{
				alert("删除失败");
			}
		},"json")
	}
</script>
</html>